﻿using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;

namespace Jerry.DroidBuilder.ThemeEditor.Converters
{
    public class DrawablePathValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var val = value as string;

            if (null == val || !val.StartsWith("@"))
            {
                return val;
            }

            var ary = val.Split('/');
            var drawables = Directory.GetFiles(@"D:\Jerry\android\apktool\framework-res\res", string.Format("{0}.*", ary[1]), SearchOption.AllDirectories);

            if (drawables.Length <= 0)
            {
                return val;
            }

            return drawables[0];
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
